package de.mindshareprojects.datawarehouse.shared;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class WebAnalyticsLineItemList {
	
	private ArrayList<WebAnalyticsLineItem> items = new ArrayList<WebAnalyticsLineItem>();

/**
 * 
 * @param campaignList ArrayList<Campaign>
 */
	public WebAnalyticsLineItemList(ArrayList<WebAnalyticsLineItem> campaignList){
		this.items = campaignList;
	}
	
	public void setItems(ArrayList<WebAnalyticsLineItem> items) {
		this.items = items;
	}

	public ArrayList<WebAnalyticsLineItem> getItems() {
		return items;
	}
	
	/**
	 * sorts CampaignList 
	 */
	public void sort(final String criterion){
		Collections.sort(this.items, new Comparator<WebAnalyticsLineItem>(){

			@Override
			public int compare(WebAnalyticsLineItem c1, WebAnalyticsLineItem c2) {
				int result = 0;
				if(criterion.equalsIgnoreCase("placementID")){
					result = c1.getPlacementID().compareToIgnoreCase(c2.getPlacementID());
				}
				else if(criterion.equalsIgnoreCase("marketingProgram")){
					result = c1.getMarketingProgram().compareTo(c2.getMarketingProgram());
				}
				else if(criterion.equalsIgnoreCase("creative")){
					result = c1.getCreative().compareTo(c2.getCreative());
				}
				else if(criterion.equalsIgnoreCase("creativeType")){
					result = c1.getCreativeType().compareTo(c2.getCreativeType());
				}
				else if(criterion.equalsIgnoreCase("demandChannel")){
					result = c1.getDemandChannel().compareTo(c2.getDemandChannel());
				}
				else if(criterion.equalsIgnoreCase("marketingActivity")){
					result = c1.getMarketingActivity().compareTo(c2.getMarketingActivity());
				}
				else if(criterion.equalsIgnoreCase("offer")){
					result = c1.getOffer().compareTo(c2.getOffer());
				}
				else if(criterion.equalsIgnoreCase("partner")){
					result = c1.getPartner().compareTo(c2.getPartner());
				}
				else if(criterion.equalsIgnoreCase("placement")){
					result = c1.getPlacement().compareTo(c2.getPlacement());
				}
				else if(criterion.equalsIgnoreCase("targetURL")){
					result = c1.getTargetURL().compareTo(c2.getTargetURL());
				}
				return result;
			}
		});
	}
	
	/**
	 * reverses the order
	 */
	public void reverse(){
		Collections.reverse(this.items);
	}
}
